<?php

namespace App\Model;

use Illuminate\Http\Request;

class RoomReport extends BaseModel
{
    protected $table = 'room_report';
    public $timestamps = false;
    
    protected $fillable = ['dispose','dispose_desc'];
    private $fields = ['*'];
    
    public function getPicsAttribute($value){
        $value = json_decode($value,true);
        if(!empty($value)){
            return $value[0];
        }
        return '';
    }
    
    
    public function getList(Request $request){
        $limit = $request->input('limit',10);
        $page = $request->input('page', 1);
        $dispose = $request->input('dispose');
        $uuid = $request->input('uuid','');
        
        $query = new RoomReport();
        
        // todo 搜索
        if($dispose) $query = $query->where(['dispose' => $dispose]);
    
        return $query->orderBy('id','DESC')->whereHas('reportUser',function($query) use($uuid){
            if($uuid) $query->where('uuid',$uuid);
        })->with(['room','reportUser'])->paginate($limit, $this->fields,'page',$page);
    }
    
    public function room(){
        return $this->belongsTo(Rooms::class, 'report_room_id', 'room_id');
    }
    
    public function reportUser(){
        return $this->belongsTo(Number::class,'user_id','user_id');
    }


    //更新
    public function updateData($data)
    {
        return curl_request(getKkaudioApiUrl() . '/inner/room/report/update', $data, 'urlencoded', 'GET');
    }



}
